import requests

from bs4 import BeautifulSoup

url = 'http://127.0.0.1:5000'
res = requests.get(url)
# 通过features指定解析器，默认解析器lxml，但是虚拟环境中需要自己安装lxml
soup = BeautifulSoup(res.text, features='lxml')
beautiful_soup = soup.prettify()
print(beautiful_soup)

# print(dir(beautiful_soup))

# title_tag = soup.find("title")
# print(title_tag.name, title_tag.text, title_tag.attrs)
# links = soup.find_all("a")
# for link in links:
#     print(link.attrs.get("href"))

# title_tag = soup.select_one("title")
# print(title_tag.name, title_tag.text, title_tag.attrs)
# links = soup.select(".container ul li a")
# print(links)
# for link in links:
#     print(link.attrs.get("href"))

# print(dir(soup.css))
container_tag = soup.select_one(".container")
for section in container_tag.children:
    if section.name:
        print(section.h1.text)
